package org.monitor.ctx;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class WebEnvCtx {
	
	private static WebEnvCtx instance = new WebEnvCtx();

	private ThreadLocal<HttpServletRequest> reqs = new ThreadLocal<HttpServletRequest>();
	private ThreadLocal<HttpServletResponse> resps = new ThreadLocal<HttpServletResponse>();
	
	public static WebEnvCtx get() {
		return instance;
	}

	void init(HttpServletRequest req, HttpServletResponse resp) {
		reqs.set(req);
		resps.set(resp);
	}
	
	public HttpServletRequest getRequest(){
		return reqs.get();
	}
	
	public HttpServletResponse getResponse(){
		return resps.get();
	}
	
	public String getWebRoot(){
		return this.getClass().getClassLoader().getResource("/").getPath();
	}
}
